//
//  OrderTableViewCell.m
//  YiBaoStore
//
//  Created by 吕清毅 on 2018/10/7.
//  Copyright © 2018年 小河. All rights reserved.
//

#import "OrderTableViewCell.h"

@implementation OrderTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = TotalWhite;
        [self setMainView];
    }
    return  self;
}

- (void)setMainView
{
//    if (!self.lineView) {
//        self.lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 10)];
//        self.lineView.backgroundColor = UIColorFromHex(0xF7F7F7);
//        [self addSubview:self.lineView];
//    }
//    if (!self.orderCodeLab) {
//        self.orderCodeLab = [UILabel new];
//        self.orderCodeLab.textColor = UIColorFromHex(0x999999);
//        self.orderCodeLab.font = FontWithSize(16);
//        self.orderCodeLab.attributedText = [TTKUtil getAtttributeStringWithLineSpace:0 kern:-0.8 and:@"订单号：2087234839458"];
//        [self addSubview:self.orderCodeLab];
//    }
//    if (!self.statueLab) {
//        self.statueLab = [UILabel new];
//        self.statueLab.textColor = goldColor;
//        self.statueLab.font = FontWithSize(14);
//        self.statueLab.text = @"已发货";
//        self.statueLab.textAlignment = NSTextAlignmentRight;
//        [self addSubview:self.statueLab];
//    }
//    if (!self.timeLab) {
//        self.timeLab = [UILabel new];
//        self.timeLab.textColor = UIColorFromHex(0x999999);
//        self.timeLab.font = FontWithSize(12);
//        self.timeLab.attributedText = [TTKUtil getAtttributeStringWithLineSpace:0 kern:-0.6 and:@"2018-08-25 16:39:30"];
//        [self addSubview:self.timeLab];
//    }
//    if (!self.midLine) {
//        self.midLine = [UIView new];
//        self.midLine.backgroundColor = UIColorFromHex(0xF7F7F7);
//        [self addSubview:self.midLine];
//    }
    if (!self.goodsBackView) {
        self.goodsBackView = [UIView new];
        self.goodsBackView.backgroundColor = TotalWhite;
        [self addSubview:self.goodsBackView];
    }
    if (!self.iconIV) {
        self.iconIV = [UIImageView new];
        self.iconIV.backgroundColor = goldColor;
        [self.goodsBackView addSubview:self.iconIV];
    }
    if (!self.titleLab) {
        self.titleLab = [UILabel new];
        self.titleLab.textColor = titleColor;
        self.titleLab.font = FontMediumWithSize(14);
        self.titleLab.numberOfLines = 0;
        self.titleLab.text = @"日本TOTES洁肤仪，使用硅胶触面材质，天天气泡，皮肤用完超级滑顺。";
        [self.goodsBackView addSubview:self.titleLab];
    }
    if (!self.numLab) {
        self.numLab = [UILabel new];
        self.numLab.textColor = titleColor;
        self.numLab.font = FontMediumWithSize(14);
        self.numLab.text = @"*2";
        self.numLab.textAlignment = NSTextAlignmentLeft;
        [self.goodsBackView addSubview:self.numLab];
    }
    if (!self.priceLab) {
        self.priceLab = [UILabel new];
        self.priceLab.textColor = titleColor;
        self.priceLab.font = FontMediumWithSize(14);
        self.priceLab.text = @"¥198";
        self.priceLab.textAlignment = NSTextAlignmentRight;
        [self.goodsBackView addSubview:self.priceLab];
    }
    /*
    if (!self.addressView) {
        self.addressView = [UIView new];
        self.addressView.backgroundColor = UIColorFromHex(0xFAFAFA);
        [self addSubview:self.addressView];
    }
    if (!self.addIV) {
        self.addIV = [UIImageView new];
        self.addIV.image = [UIImage imageNamed:@"address"];
        [self.addressView addSubview:self.addIV];
    }
    if (!self.addressLab) {
        self.addressLab = [UILabel new];
        self.addressLab.textColor = UIColorFromHex(0x999999);
        self.addressLab.font = FontMediumWithSize(12);
        NSString *content = @"陈典军，1885486262，杭州市拱墅区莫干山路103号大塘新村612室";
        self.addressLab.text = content;
        self.addressLab.numberOfLines = 0;
        [self.addressView addSubview:self.addressLab];
    }
    if (!self.bottomView) {
        self.bottomView = [UIView new];
        self.bottomView.backgroundColor = TotalWhite;
        [self addSubview:self.bottomView];
        
        CGFloat padding = (SCREENWIDTH-30-36-83)/2;
        NSArray *imageArray = @[@"orderMoney",@"goodsMoney",@"profitMoney"];
        NSArray *titleArray = @[@"订单金额",@"货款金额",@"收益金额"];
        NSArray *desArray = @[@"¥396",@"¥300",@"¥96"];
        for (int i = 0; i < 3; i++) {
            UIImageView *imageV = [UIImageView new];
            imageV.frame = CGRectMake(30+(padding+12)*i, 15, 12, 12);
            imageV.backgroundColor = ClearColor;
            imageV.image = [UIImage imageNamed:imageArray[i]];
            [self.bottomView addSubview:imageV];
            
            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(imageV.right+5, imageV.top, 48, 12)];
            label.textColor = UIColorFromHex(0x7777777);
            label.font = FontWithSize(12);
            label.text = titleArray[i];
            [self.bottomView addSubview:label];
            
            UILabel *desLabel = [[UILabel alloc]initWithFrame:CGRectMake(label.left, label.bottom+8, 80, 14)];
            desLabel.tag = 90+i;
            desLabel.textColor = titleColor;
            desLabel.font = [UIFont systemFontOfSize:14];
            desLabel.text = desArray[i];
            [self.bottomView addSubview:desLabel];
            if (i == 0) {
                self.orderIV = imageV;
                self.orderTitle = label;
                self.orderMoney = desLabel;
            }else if (i == 1)
            {
                self.goodsIV = imageV;
                self.goodsTitle = label;
                self.goodsMoney = desLabel;
            }else
            {
                self.profitIV = imageV;
                self.profitTitle = label;
                self.profitMoney = desLabel;
            }
        }
    }
     */
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.goodsBackView.frame = CGRectMake(0, 0, self.width, 90);
    self.iconIV.frame = CGRectMake(15, 0, 65, 65);
    CGFloat width = self.width-15-65-10-15;
    self.titleLab.frame = CGRectMake(self.iconIV.right+10, 0, width, 40);
    self.numLab.frame = CGRectMake(self.width-45, self.titleLab.bottom+12, 30, 14);
    self.priceLab.frame = CGRectMake(self.width-self.numLab.width-15-10-80, self.numLab.top, 80, 14);
}

- (void)getModel:(GoodsModel *)model
{
    self.model = model;
    [self.iconIV sd_setImageWithURL:[NSURL URLWithString:model.itemShowImage] placeholderImage:[UIImage imageNamed:@"Placeholder100"]];
    self.titleLab.text = [NSString stringWithFormat:@"%@",model.itemTitle];
    self.priceLab.text = [NSString stringWithFormat:@"¥%.2f",model.itemPrice];
    self.numLab.text = [NSString stringWithFormat:@"*%li",model.itemBuyAmount];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
